
module wjl {
    export class PlayMediatorWJL extends BaseMediator {
        public static NAME: string = "PlayMediatorWJL";

        public constructor(viewComponent: any = null) {
            super(PlayMediatorWJL.NAME, viewComponent);
        }
        public listNotificationInterests(): Array<any> {
            return [
                PanelNotify.HALL.STAGE_RESIZE,
                PanelNotify.WJL.CLOSE_PLAY_GAME,
                PanelNotify.WJL.JOIN_ROOM,
                PanelNotify.WJL.START_GAME,
                PanelNotify.WJL.BET_RECEIVE,
                PanelNotify.WJL.GAME_OVER,
                PanelNotify.WJL.WAIT_NEXT_GAME,
                PanelNotify.WJL.WAIT_START_GAME,
                PanelNotify.WJL.DATA_RECOVERY,
                PanelNotify.WJL.GET_SERIAL_NUMBER,
                PanelNotify.WJL.RECEIVE_LUDAN,
                PanelNotify.WJL.RECEIVE_USER_LIST
            ]
        }
        public playPanel: PlayPanelWJL;//基础面板
        private bet_chip = [100, 1000, 5000, 10000, 50000];//筹码规格
        private betImgArr: Array<Array<eui.Image>> = [[], [], [], [], [], []];//6个筹码区域的图片都放在这个数组，结算动画匹配5个输家数组种图片飞向庄家，庄家赔钱飞向赢家数组
        private pokerXY = [];//所有扑克牌在UI中的坐标，发牌动画时用到
        private globLook: boolean = false;//结算过程金额不准变动
        /**
         * 下注区域对应后端值
      * cmd.AREA_XIAN = 0 --闲家索引  
        cmd.AREA_PING = 1 --平家索引
        cmd.AREA_ZHUANG = 2 --庄家索引
        cmd.AREA_XIAN_TIAN = 3 --闲天王
        cmd.AREA_ZHUANG_TIAN = 4 --庄天王
        cmd.AREA_TONG_DUI = 5 --同点平
        cmd.AREA_XIAN_DUI = 6 --闲对子
        cmd.AREA_ZHUANG_DUI = 7 --庄对子
        cmd.AREA_XINGYUN = 8 --幸运6
        cmd.AREA_MAX = 9 --最大区域
         */
        public handleNotification(notification: puremvc.INotification): void {
            switch (notification.getName()) {
                case PanelNotify.HALL.STAGE_RESIZE:
                    if (this.playPanel) {
                        this.playPanel.width = GameConfig.curWidth()
                        this.playPanel.height = GameConfig.curHeight()
                    }
                    break;
                case PanelNotify.WJL.CLOSE_PLAY_GAME:
                    this.destroy();
                    break;
                case PanelNotify.WJL.JOIN_ROOM:
                    if (this.playPanel && this.playPanel.parent) {
                        this.initUserInfo();
                    } else {//游戏中途加入有可能 先进玩家后加载房间数据，这时候面板还没起来。后台BUG
                        this.playPanel = null;
                        this.playPanel = new PlayPanelWJL();
                        this.showUI(this.playPanel, 2, 5);
                        game.AppFacade.instance.sendNotification(PanelNotify.HALL.JOIN_GAME_BY_HALL)
                    }
                    break;
                case PanelNotify.WJL.START_GAME:
                    this.gameStart()
                    break;
                case PanelNotify.WJL.BET_RECEIVE:
                    this.betReceive()
                    break;
                case PanelNotify.WJL.GAME_OVER:
                    this.gameOver()
                    break;
                case PanelNotify.WJL.WAIT_NEXT_GAME:
                    this.waitNextGame();
                    break;
                case PanelNotify.WJL.WAIT_START_GAME:
                    this.waitStartGame();
                    break;
                case PanelNotify.WJL.DATA_RECOVERY:
                    this.dataRecovery();
                    break;
                case PanelNotify.WJL.GET_SERIAL_NUMBER:
                    this.initRoomInfo();
                    break;
                case PanelNotify.WJL.RECEIVE_LUDAN:
                    this.shouLuDan();
                    break;
                case PanelNotify.WJL.RECEIVE_USER_LIST:
                    this.receiveUserList();
                    break;
            }
        }

        /**
         * 初始化面板ui
         */
        public initUI(): void {
            //切换音乐
            if (InstructionsEnum.SOUND_GAME != InstructionsEnum.GAME_SOUND_NAME.WJL) {
                SoundManage.stopYinYue();
                InstructionsEnum.SOUND_GAME = InstructionsEnum.GAME_SOUND_NAME.WJL;
                SoundManage.startYinYueLoad();
            }
            //将滚动公告转移到当前面板
            EffectUtils.moveNoticeToPanel(this.playPanel.noticeGroup)

            this.playPanel.bet_button_0.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRectClick, this)
            this.playPanel.bet_button_1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRectClick, this)
            this.playPanel.bet_button_2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRectClick, this)
            this.playPanel.bet_button_3.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRectClick, this)
            this.playPanel.bet_button_4.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRectClick, this)
            this.playPanel.bet_button_5.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRectClick, this)
            this.playPanel.bet_button_group.addEventListener(egret.TouchEvent.TOUCH_TAP, this.betGroupClick, this)

            this.playPanel.menu_button.addEventListener(egret.TouchEvent.TOUCH_TAP, this.menu_click, this)
            this.playPanel.menu_fankui.addEventListener(egret.TouchEvent.TOUCH_TAP, this.fankuiClick, this)
            this.playPanel.menu_jilu.addEventListener(egret.TouchEvent.TOUCH_TAP, this.jiluClick, this)
            this.playPanel.menu_set.addEventListener(egret.TouchEvent.TOUCH_TAP, this.setClick, this)
            this.playPanel.menu_help.addEventListener(egret.TouchEvent.TOUCH_TAP, this.helpClick, this)
            this.playPanel.menu_exit.addEventListener(egret.TouchEvent.TOUCH_TAP, this.exitClick, this)
            this.playPanel.otherUserImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.userListClic, this)
            this.pokerXY =
                [
                    [
                        { x: this.playPanel.poker_xian_0.x, y: this.playPanel.poker_xian_0.y },
                        { x: this.playPanel.poker_xian_1.x, y: this.playPanel.poker_xian_1.y },
                        { x: this.playPanel.poker_xian_2.x, y: this.playPanel.poker_xian_2.y }
                    ],
                    [
                        { x: this.playPanel.poker_zhuang_0.x, y: this.playPanel.poker_zhuang_0.y },
                        { x: this.playPanel.poker_zhuang_1.x, y: this.playPanel.poker_zhuang_1.y },
                        { x: this.playPanel.poker_zhuang_2.x, y: this.playPanel.poker_zhuang_2.y }
                    ]
                ]
        }
        /**
         * 初始化面板数据
         */
        public initData(): void {
            InstructionsEnum.isHall = true;
            this.globLook = false;
            this.clearData();
            this.initUserInfo();
        }
        //初始化页面数据
        private clearData() {
            this.globLook = false
            this.playPanel.bet_num_0.text = "";
            this.playPanel.bet_num_1.text = "";
            this.playPanel.bet_num_2.text = "";
            this.playPanel.bet_num_3.text = "";
            this.playPanel.bet_num_4.text = "";
            this.playPanel.bet_num_5.text = "";
            this.playPanel.bet_num_0_my.text = "";
            this.playPanel.bet_num_1_my.text = "";
            this.playPanel.bet_num_2_my.text = "";
            this.playPanel.bet_num_3_my.text = "";
            this.playPanel.bet_num_4_my.text = "";
            this.playPanel.bet_num_5_my.text = "";
            this.playPanel.my_betNum.text = "";
            this.playPanel.ludan_group.visible = true;
            this.playPanel.poker_group.visible = false;
            this.playPanel.xian_dian.text = ""
            this.playPanel.xian_dian.scaleX = 1
            this.playPanel.zhuang_dian.text = ""
            this.playPanel.zhuang_dian.scaleX = 1
            this.playPanel.win_img.source = ""
            for (let i = 0; i < 3; i++) {
                this.playPanel["poker_xian_" + i].x = 1130;
                this.playPanel["poker_xian_" + i].y = 100;
                this.playPanel["poker_xian_" + i].source = "poker_back";
                this.playPanel["poker_xian_" + i].rotation = 310;
                this.playPanel["poker_xian_" + i].anchorOffsetX = "59"
                this.playPanel["poker_xian_" + i].anchorOffsetY = "73"
                this.playPanel["poker_xian_" + i].scaleX = 0.2;
                this.playPanel["poker_xian_" + i].scaleY = 0.2;
                this.playPanel["poker_xian_" + i].visible = false;
            }
            for (let i = 0; i < 3; i++) {
                this.playPanel["poker_zhuang_" + i].x = 1130;
                this.playPanel["poker_zhuang_" + i].y = 100;
                this.playPanel["poker_zhuang_" + i].source = "poker_back";
                this.playPanel["poker_zhuang_" + i].rotation = 310;
                this.playPanel["poker_zhuang_" + i].anchorOffsetX = "59"
                this.playPanel["poker_zhuang_" + i].anchorOffsetY = "73"
                this.playPanel["poker_zhuang_" + i].scaleX = 0.2;
                this.playPanel["poker_zhuang_" + i].scaleY = 0.2;
                this.playPanel["poker_zhuang_" + i].visible = false
            }
            this.playPanel.timeOut.destroy()
            this.playPanel.score_user.text = "";
            this.playPanel.xiazhu_tips.source = "";
            this.betImgArr = [[], [], [], [], [], []];
            this.playPanel.bet_img_group.removeChildren();
            this.playPanel.title.visible = false;
            this.playPanel.title.x = - (this.playPanel.title.width);
            this.IsUserScore(0)
        }
        //销毁UI
        public destroy(): void {
            InstructionsEnum.isHall = false;
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.CLOSE_HELP);
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.CLOSE_USER_LIST);
            this.closePanel(1);
        }
        //玩家信息
        private initUserInfo() {
            //玩家信息
            this.playPanel.userName.text = Global.cutString(GameVO.getVo().szNickName + "");
            this.playPanel.userImg.source = "special_" + GameVO.getVo().wFaceID % 15;
            if (WjlVO.getVo().structUserList) {
                this.playPanel.otherUserNum.text = WjlVO.getVo().structUserList.length + ""
            }
            if (this.globLook == false) {
                this.playPanel.userMoney.text = WjlVO.getVo().lUserScore / 100 + "";
            }
        }
        //房间信息
        private initRoomInfo() {
            this.playPanel.bet_num_0.text = "" + WjlVO.getVo().betNumAdds_0 / 100 + "/";
            this.playPanel.bet_num_1.text = "" + WjlVO.getVo().betNumAdds_1 / 100 + "/";
            this.playPanel.bet_num_2.text = "" + WjlVO.getVo().betNumAdds_2 / 100 + "/";
            this.playPanel.bet_num_3.text = "" + WjlVO.getVo().betNumAdds_3 / 100 + "/";
            this.playPanel.bet_num_4.text = "" + WjlVO.getVo().betNumAdds_4 / 100 + "/";
            this.playPanel.bet_num_5.text = "" + WjlVO.getVo().betNumAdds_5 / 100 + "/";

            this.playPanel.bet_num_0_my.text = WjlVO.getVo().betNumAdds_0_my / 100 + "";
            this.playPanel.bet_num_1_my.text = WjlVO.getVo().betNumAdds_1_my / 100 + "";
            this.playPanel.bet_num_2_my.text = WjlVO.getVo().betNumAdds_2_my / 100 + "";
            this.playPanel.bet_num_3_my.text = WjlVO.getVo().betNumAdds_3_my / 100 + "";
            this.playPanel.bet_num_4_my.text = WjlVO.getVo().betNumAdds_4_my / 100 + "";
            this.playPanel.bet_num_5_my.text = WjlVO.getVo().betNumAdds_5_my / 100 + "";

            this.playPanel.my_betNum.text = "" + WjlVO.getVo().betNumAdds_my / 100;
            this.playPanel.bianhao.text = "局号：" + WjlVO.getVo().gameNumbering;
        }
        //游戏开始
        private gameStart() {
            SoundManage.startYinxiaoLoad("wjl_gameStart_mp3");
            var thisBack = this;
            thisBack.clearData();
            thisBack.playPanel.xiazhu_tips.source = "timeState_xiazhu";
            thisBack.playPanel.timeOut.init(WjlVO.getVo().cbTimeLeave, true)
            thisBack.playPanel.title.source = "wjl_ksxz"
            thisBack.playPanel.title.visible = true;
            egret.Tween.get(thisBack.playPanel.title).to({ x: GameConfig.curWidth() / 2 - thisBack.playPanel.title.width / 2 }, 300).wait(500).to({ x: GameConfig.curWidth() }, 300).call(() => {
                thisBack.playPanel.title.visible = false;
                thisBack.playPanel.title.x = -(thisBack.playPanel.title.width);
                thisBack.IsUserScore(WjlVO.getVo().lUserScore, false, true)
                SoundManage.startYinxiaoLoad("c_place_cn_mp3");
            })
            if (WjlVO.getVo().gameNum >= 6) {
                let data = {
                    wTableID: WjlVO.getVo().wTableId,
                    wChairID: WjlVO.getVo().wChairId,
                    cbForceLeave: 1
                }
                SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.WJL, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                Global.tipShow("您已经连续 5 局未下注，被请离了游戏桌")
            } else if (WjlVO.getVo().gameNum == 4) {
                Global.tipShow("您已经连续 3 局未下注，连续 5 局未下注将被请离游戏桌!")
            }
        }
        //下注返回
        private betReceive() {
            this.initRoomInfo();
            let startX, startY, rect: eui.Rect, arr: Array<eui.Image>;//筹码飞行动画起始位置，结束位置,结束区域宽高,装筹码的数组
            let betUser = WjlVO.getVo().betUser;
            let betAdds = WjlVO.getVo().betAdds;
            let betNum = WjlVO.getVo().betNum;
            let isMy = false;
            if (betUser == WjlVO.getVo().wChairId) {
                this.playPanel.userMoney.text = WjlVO.getVo().lUserScore / 100 + "";
                this.IsUserScore(WjlVO.getVo().lUserScore, true)
                startX = this.playPanel.userInfo.x + 60 - this.playPanel.bet_img_group.x
                startY = this.playPanel.userInfo.y - 25 - this.playPanel.bet_img_group.y;
                isMy = true;
            } else {
                startX = this.playPanel.otherUserImg.x - 25 - this.playPanel.bet_img_group.x;
                startY = this.playPanel.otherUserImg.y - 25 - this.playPanel.bet_img_group.y;
            }
            switch (betAdds) {
                case 6://闲对子
                    rect = this.playPanel.fanwei_0
                    arr = this.betImgArr[0];
                    break;
                case 1://和
                    rect = this.playPanel.fanwei_1
                    arr = this.betImgArr[1];
                    break;
                case 7://庄对子
                    rect = this.playPanel.fanwei_2
                    arr = this.betImgArr[2];
                    break;
                case 0://闲
                    rect = this.playPanel.fanwei_3
                    arr = this.betImgArr[3];
                    break;
                case 8://辛运6
                    rect = this.playPanel.fanwei_4
                    arr = this.betImgArr[4];
                    break;
                case 2://庄
                    rect = this.playPanel.fanwei_5
                    arr = this.betImgArr[5];
                    break;
            }
            if (Global.isNotEmpty(arr)) {
                let imgArr = this.qiegeJinbi(betNum);
                for (let y = 0; y < imgArr.length; y++) {
                    let img = betImgPool.getFreeObject("bet_" + (imgArr[y] / 100))
                    img.x = startX;
                    img.y = startY;
                    img.width = 50;
                    img.height = 50;
                    img.visible = false;
                    img.name = betUser + "";//记住是谁下的注，庄家赔钱时这个注要飞向下注那个玩家
                    this.playPanel.bet_img_group.addChild(img);
                    arr.push(img)
                    egret.Tween.get(img).wait(isMy ? 0 : this.random_num(50, 700))
                        .to({ visible: true })
                        .to({ x: rect.x + rect.width * Math.random(), y: rect.y + rect.height * Math.random() }, 500, egret.Ease.circInOut).call((img: eui.Image) => {
                            egret.Tween.removeTweens(img);
                        }, this, [img]);
                    if (Math.random() < 0.2) {//筹码太多,声音随机次数播放,降低性能消耗
                        let t = egret.setTimeout(() => {
                            SoundManage.startYinxiaoLoad("wjl_add_bet_mp3");
                            egret.clearTimeout(t)
                        }, this, this.random_num(10, 800))
                    }
                }
            }
        }
        //游戏结算
        private gameOver() {
            this.globLook = true;
            this.IsUserScore(0)
            var thisBack = this;
            thisBack.playPanel.xiazhu_tips.source = "timeState_fapai";
            thisBack.playPanel.timeOut.init(WjlVO.getVo().cbTimeLeave)
            var zhuangNum = 0
            var xianNum = 0
            var zhuangDuizi = false
            var xianDuizi = false
            //停止下注动画
            var stopBet = () => {
                thisBack.playPanel.title.source = "wjl_tzxz"
                thisBack.playPanel.title.visible = true;
                egret.Tween.get(thisBack.playPanel.title).to({ x: GameConfig.curWidth() / 2 - thisBack.playPanel.title.width / 2 }, 300).wait(500).to({ x: GameConfig.curWidth() }, 300).call(() => {
                    thisBack.playPanel.title.visible = false;
                    thisBack.playPanel.title.x = -(thisBack.playPanel.title.width);
                    fapai();
                })
            }
            //发牌报点
            var fapai = () => {
                thisBack.playPanel.ludan_group.visible = false;
                thisBack.playPanel.poker_group.visible = true;
                let xian_leng = WjlVO.getVo().poker_xian.length
                let zhuang_leng = WjlVO.getVo().poker_zhuang.length
                var xian_pokerObjArr = Poker_public.idChangeObject(WjlVO.getVo().poker_xian)
                var zhuang_pokerObjArr = Poker_public.idChangeObject(WjlVO.getVo().poker_zhuang)

                let num = xian_leng + zhuang_leng;

                //找出最后一张扑克，动画结束时这张扑克需要调用后续的事件
                let end_poker: eui.Image = null;
                if (num == 4) {
                    end_poker = thisBack.playPanel.poker_zhuang_1;
                } else if (num == 6) {
                    end_poker = thisBack.playPanel.poker_zhuang_2;
                } else if (num == 5) {
                    if (xian_leng == 3) {
                        end_poker = thisBack.playPanel.poker_xian_2;
                    } else {
                        end_poker = thisBack.playPanel.poker_zhuang_2;
                    }
                }
                //翻闲家牌
                for (let i = 0; i < xian_leng; i++) {
                    let poker: eui.Image = thisBack.playPanel["poker_xian_" + i];
                    let source = Global.getPokerById(WjlVO.getVo().poker_xian[i]);
                    egret.Tween.get(poker).wait(i * 2000).to({ visible: true }).call(() => {
                        SoundManage.startYinxiaoLoad("wjl_send_poker_mp3");
                    }).to({ x: thisBack.pokerXY[0][i].x, y: thisBack.pokerXY[0][i].y, scaleX: 1, scaleY: 1, rotation: 0 }, 300).call((poker, source, num) => {
                        if (poker == end_poker) {//翻到最后一张牌动画结束后调用后续事件
                            EffectUtils.xuanZuanHuanTu(poker, source, 300, winBetadds)
                        } else {
                            EffectUtils.xuanZuanHuanTu(poker, source)
                        }
                        xianNum = Number(thisBack.baodian(xian_pokerObjArr, num, 0))
                    }, this, [poker, source, i + 1])
                }
                //翻庄家牌
                for (let i = 0; i < zhuang_leng; i++) {
                    let poker: eui.Image = thisBack.playPanel["poker_zhuang_" + i];
                    let source = Global.getPokerById(WjlVO.getVo().poker_zhuang[i]);
                    egret.Tween.get(poker).wait(i * 2000 + 1000).to({ visible: true }).call(() => {
                        SoundManage.startYinxiaoLoad("wjl_send_poker_mp3");
                    }).to({ x: thisBack.pokerXY[1][i].x, y: thisBack.pokerXY[1][i].y, scaleX: 1, scaleY: 1, rotation: 0 }, 300).call((poker, source, num) => {
                        if (poker == end_poker) {
                            EffectUtils.xuanZuanHuanTu(poker, source, 300, winBetadds)
                        } else {
                            EffectUtils.xuanZuanHuanTu(poker, source)
                        }
                        zhuangNum = Number(thisBack.baodian(zhuang_pokerObjArr, num, 1))
                    }, this, [poker, source, i + 1])
                }
            }
            let xianBetAddsArr: Array<number> = [];//闲家要收取的筹码区域
            //赢钱区域特效
            var winBetadds = () => {
                let winArr = [];
                if (WjlVO.getVo().score_arr[0] > 0) {//闲
                    winArr.push(thisBack.playPanel.bet_button_3)
                    xianBetAddsArr.push(3)
                    thisBack.playPanel.win_img.source = "wjl_xy"
                    SoundManage.startYinxiaoLoad("ba_pwin_cn_mp3");
                }
                if (WjlVO.getVo().score_arr[1] > 0) {//和
                    winArr.push(thisBack.playPanel.bet_button_1)
                    xianBetAddsArr.push(1)
                    thisBack.playPanel.win_img.source = "wjl_hepj"
                    SoundManage.startYinxiaoLoad("ba_tiwin_cn_mp3");
                }
                if (WjlVO.getVo().score_arr[2] > 0) {//庄
                    winArr.push(thisBack.playPanel.bet_button_5)
                    xianBetAddsArr.push(5)
                    thisBack.playPanel.win_img.source = "wjl_zy"
                    SoundManage.startYinxiaoLoad("ba_bwin_cn_mp3");
                }
                if (WjlVO.getVo().score_arr[6] > 0) {//闲对子
                    winArr.push(thisBack.playPanel.bet_button_0)
                    xianBetAddsArr.push(0)
                    xianDuizi = true;
                }
                if (WjlVO.getVo().score_arr[7] > 0) {//庄对子
                    winArr.push(thisBack.playPanel.bet_button_2)
                    xianBetAddsArr.push(2)
                    zhuangDuizi = true;
                }
                if (WjlVO.getVo().score_arr[8] > 0) {//辛运6
                    winArr.push(thisBack.playPanel.bet_button_4)
                    xianBetAddsArr.push(4)
                }
                for (let i = 0; i < winArr.length; i++) {
                    if (winArr.length - i == 1) {
                        EffectUtils.Twinkle(winArr[i], 3, 200, shouChouMa_zhuang);
                    } else {
                        EffectUtils.Twinkle(winArr[i]);
                    }
                }
                EffectUtils.Twinkle(thisBack.playPanel.win_img)
            }
            //收筹码-庄
            var shouChouMa_zhuang = () => {
                thisBack.playPanel.xiazhu_tips.source = "timeState_paijiang";
                for (let i = 0; i < thisBack.betImgArr.length; i++) {
                    if (xianBetAddsArr.indexOf(i) == -1) {
                        let imgArr: Array<eui.Image> = thisBack.betImgArr[i]
                        for (let j = 0; j < imgArr.length; j++) {
                            egret.Tween.get(imgArr[j]).to({ x: 617, y: 195 }, 300).call((img: eui.Image) => {
                                egret.Tween.removeTweens(img);
                                if (thisBack.playPanel.bet_img_group.contains(img)) {
                                    thisBack.playPanel.bet_img_group.removeChild(img);
                                    betImgPool.returnObject(img)
                                }
                            }, this, [imgArr[j]])
                            if (Math.random() * 100 < 5) {//筹码太多,声音随机次数播放,降低性能消耗
                                let t = egret.setTimeout(() => {
                                    SoundManage.startYinxiaoLoad("wjl_add_bet_mp3");
                                    egret.clearTimeout(t)
                                }, this, this.random_num(10, 800))
                            }
                        }
                    }
                }
                egret.setTimeout(peiChouMa, this, 800)
            }
            //赔筹码
            var peiChouMa = () => {
                let rect: eui.Rect, imgArr: Array<eui.Image>, peilv: number;//筹码飞行动画结束位置,结束区域宽高,装筹码的数组,赔率
                for (let i = 0; i < thisBack.betImgArr.length; i++) {
                    if (xianBetAddsArr.indexOf(i) != -1) {//此区域要赔钱
                        switch (i) {
                            case 0://闲对子
                                rect = this.playPanel.fanwei_0
                                peilv = 11
                                break;
                            case 1://和
                                rect = this.playPanel.fanwei_1
                                peilv = 8
                                break;
                            case 2://庄对子
                                rect = this.playPanel.fanwei_2
                                peilv = 11
                                break;
                            case 3://闲
                                rect = this.playPanel.fanwei_3
                                peilv = 1
                                break;
                            case 4://辛运6
                                rect = this.playPanel.fanwei_4
                                peilv = 13
                                if (WjlVO.getVo().poker_zhuang.length == 3) {
                                    peilv = 21
                                }
                                break;
                            case 5://庄
                                rect = this.playPanel.fanwei_5
                                peilv = 1
                                break;
                        }
                        imgArr = thisBack.betImgArr[i];
                        let num = imgArr.length;//查看该区域当前有多少个筹码
                        for (let j = 0; j < num; j++) {
                            for (let y = 0; y < peilv; y++) {//按照赔率和当前的已有筹码相同的图片生成新的筹码
                                var img = betImgPool.getFreeObject(imgArr[j].source + "")
                                img.x = 617;
                                img.y = 195;
                                img.width = 50;
                                img.height = 50;
                                img.name = imgArr[j].name;//记住是谁下的注，庄家赔钱时这个注要飞向下注那个玩家
                                this.playPanel.bet_img_group.addChild(img);
                                imgArr.push(img)
                                egret.Tween.get(img).wait(this.random_num(50, 700))
                                    .to({ x: rect.x + rect.width * Math.random(), y: rect.y + rect.height * Math.random() }, 500, egret.Ease.circInOut).call((img: eui.Image) => {
                                        egret.Tween.removeTweens(img);
                                    }, this, [img]);
                            }
                            if (Math.random() * 100 < 5) {//筹码太多,声音随机次数播放,降低性能消耗
                                let t = egret.setTimeout(() => {
                                    SoundManage.startYinxiaoLoad("wjl_add_bet_mp3");
                                    egret.clearTimeout(t)
                                }, this, this.random_num(10, 800));
                            }
                        }
                    }
                }
                egret.setTimeout(shouChouMa_xian, this, 1200)
            }
            //收筹码-闲
            var shouChouMa_xian = () => {
                for (let i = 0; i < thisBack.betImgArr.length; i++) {
                    if (xianBetAddsArr.indexOf(i) != -1) {
                        let imgArr = thisBack.betImgArr[i];
                        for (let i = 0; i < imgArr.length; i++) {
                            var x = this.playPanel.otherUserImg.x - 25 - this.playPanel.bet_img_group.x
                            var y = this.playPanel.otherUserImg.y - 25 - this.playPanel.bet_img_group.y
                            if (imgArr[i].name == WjlVO.getVo().wChairId + "") {
                                x = this.playPanel.userInfo.x + 60 - this.playPanel.bet_img_group.x
                                y = this.playPanel.userInfo.y - 25 - this.playPanel.bet_img_group.y
                            }
                            egret.Tween.get(imgArr[i]).wait(this.random_num(50, 700)).to({ x: x, y: y }, 800, egret.Ease.backInOut).call((img: eui.Image) => {
                                egret.Tween.removeTweens(img);
                                if (thisBack.playPanel.bet_img_group.contains(img)) {
                                    thisBack.playPanel.bet_img_group.removeChild(img);
                                    betImgPool.returnObject(img)
                                }
                            }, this, [imgArr[i]]);
                            if (Math.random() * 100 < 5) {//筹码太多,声音随机次数播放,降低性能消耗
                                let t = egret.setTimeout(() => {
                                    SoundManage.startYinxiaoLoad("wjl_add_bet_mp3");
                                    egret.clearTimeout(t)
                                }, this, this.random_num(10, 800))
                            }
                        }
                    }
                }
                //飘分数
                thisBack.playPanel.score_user.text = Global.getmeishufen(WjlVO.getVo().score_my / 100)
                EffectUtils.flyObj(thisBack.playPanel.score_user)
                //更新路单
                var obj = {
                    cbBankerCount: zhuangNum,
                    cbPlayerCount: xianNum,
                    bBankerTwoPair: zhuangDuizi,
                    bPlayerTwoPair: xianDuizi,
                    cbKingWinner: 0
                }
                if (WjlVO.getVo().ludan != null) {
                    WjlVO.getVo().ludan.unshift(obj);
                }
                this.globLook = false;
                thisBack.initUserInfo();
                thisBack.shouLuDan();
                WjlVO.getVo().game_state = 0
            }
            stopBet();
        }
        //推送场外玩家
        private receiveUserList() {
            if (WjlVO.getVo().structUserList) {
                this.playPanel.otherUserNum.text = WjlVO.getVo().structUserList.length + ""
            }
        }
        //中途加入 游戏状态
        private dataRecovery() {
            this.initRoomInfo();

            var goldArr = [
                WjlVO.getVo().betNumAdds_0,
                WjlVO.getVo().betNumAdds_1,
                WjlVO.getVo().betNumAdds_2,
                WjlVO.getVo().betNumAdds_3,
                WjlVO.getVo().betNumAdds_4,
                WjlVO.getVo().betNumAdds_5
            ]
            for (var i in goldArr) {
                var rect: eui.Rect = this.playPanel["fanwei_" + i]
                var imgArr = this.betImgArr[i];
                let betArr = this.qiegeJinbi(goldArr[i]);
                for (let y in betArr) {
                    let img = betImgPool.getFreeObject("bet_" + (betArr[y] / 100))
                    img.x = rect.x + rect.width * Math.random()
                    img.y = rect.y + rect.height * Math.random()
                    img.width = 50;
                    img.height = 50;
                    this.playPanel.bet_img_group.addChild(img);
                    imgArr.push(img)
                }
            }
            this.playPanel.timeOut.init(WjlVO.getVo().cbTimeLeave)
            this.playPanel.xiazhu_tips.source = "timeState_dengdai"
            if (WjlVO.getVo().cbGameStatus == 100) {
                this.playPanel.xiazhu_tips.source = "timeState_xiazhu";
                this.IsUserScore(WjlVO.getVo().lUserScore, false, true)
            }
        }
        //中途加入 空闲状态
        private waitNextGame() {
            this.playPanel.xiazhu_tips.source = "timeState_dengdai";
            this.playPanel.timeOut.init(WjlVO.getVo().cbTimeLeave);
        }
        //等待开局
        private waitStartGame() {
            this.playPanel.timeOut.init(WjlVO.getVo().cbTimeLeave);
            this.playPanel.xiazhu_tips.source = "timeState_zhunbei";
        }
        private shouLuDan() {
            //刷新路单 
            this.showZhuPanLu();
            this.showDaLu();
            this.sohwDaYanZai();
            this.showXiaoLu();
            this.showJiaYouLu();

            //查询问路
            //先模拟庄赢
            var obj = {
                cbBankerCount: 2,
                cbPlayerCount: 1,
                bBankerTwoPair: false,
                bPlayerTwoPair: false,
                cbKingWinner: 0
            }
            WjlVO.getVo().ludan.unshift(obj);
            var dayanzai_arr: Array<Array<Object>> = this.sohwDaYanZai(true);
            if (dayanzai_arr != undefined && dayanzai_arr.length != 0) {
                var dayanzai = dayanzai_arr[dayanzai_arr.length - 1][dayanzai_arr[dayanzai_arr.length - 1].length - 1];
                if (Global.isNotEmpty(dayanzai)) {
                    if (dayanzai["color"] == 0) {
                        this.playPanel.wenlu_zhuang_dayanzai.source = "wjl_dsx_h"
                    } else if (dayanzai["color"] == 1) {
                        this.playPanel.wenlu_zhuang_dayanzai.source = "wjl_dsx_l"
                    }
                }
            }
            var xiaolu_arr: Array<Array<Object>> = this.showXiaoLu(true);
            if (xiaolu_arr != undefined && xiaolu_arr.length != 0) {
                var xiaolu = xiaolu_arr[xiaolu_arr.length - 1][xiaolu_arr[xiaolu_arr.length - 1].length - 1];
                if (Global.isNotEmpty(xiaolu)) {
                    if (xiaolu["color"] == 0) {
                        this.playPanel.wenlu_zhuang_xiaolu.source = "wjl_dy_h"
                    } else if (xiaolu["color"] == 1) {
                        this.playPanel.wenlu_zhuang_xiaolu.source = "wjl_dy_l"
                    }
                }
            }
            var jiayoulu_arr: Array<Array<Object>> = this.showJiaYouLu(true);
            if (jiayoulu_arr != undefined && jiayoulu_arr.length != 0) {
                var jiayoulu = jiayoulu_arr[jiayoulu_arr.length - 1][jiayoulu_arr[jiayoulu_arr.length - 1].length - 1];
                if (Global.isNotEmpty(jiayoulu)) {
                    if (jiayoulu["color"] == 0) {
                        this.playPanel.wenlu_zhuang_jiayoulu.source = "wjl_dxx_h"
                    } else if (jiayoulu["color"] == 1) {
                        this.playPanel.wenlu_zhuang_jiayoulu.source = "wjl_dxx_l"
                    }
                }
            }
            WjlVO.getVo().ludan.shift()

            //再模拟闲赢
            var obj = {
                cbBankerCount: 1,
                cbPlayerCount: 2,
                bBankerTwoPair: false,
                bPlayerTwoPair: false,
                cbKingWinner: 0
            }
            WjlVO.getVo().ludan.unshift(obj);
            var dayanzai_arr: Array<Array<Object>> = this.sohwDaYanZai(true);
            if (dayanzai_arr != undefined && dayanzai_arr.length != 0) {
                var dayanzai = dayanzai_arr[dayanzai_arr.length - 1][dayanzai_arr[dayanzai_arr.length - 1].length - 1];
                if (Global.isNotEmpty(dayanzai)) {
                    if (dayanzai["color"] == 0) {
                        this.playPanel.wenlu_xian_dayanzai.source = "wjl_dsx_h"
                    } else if (dayanzai["color"] == 1) {
                        this.playPanel.wenlu_xian_dayanzai.source = "wjl_dsx_l"
                    }
                }
            }
            var xiaolu_arr: Array<Array<Object>> = this.showXiaoLu(true);
            if (xiaolu_arr != undefined && xiaolu_arr.length != 0) {
                var xiaolu = xiaolu_arr[xiaolu_arr.length - 1][xiaolu_arr[xiaolu_arr.length - 1].length - 1];
                if (Global.isNotEmpty(xiaolu)) {
                    if (xiaolu["color"] == 0) {
                        this.playPanel.wenlu_xian_xiaolu.source = "wjl_dy_h"
                    } else if (xiaolu["color"] == 1) {
                        this.playPanel.wenlu_xian_xiaolu.source = "wjl_dy_l"
                    }
                }
            }
            var jiayoulu_arr: Array<Array<Object>> = this.showJiaYouLu(true);
            if (jiayoulu_arr != undefined && jiayoulu_arr.length) {
                var jiayoulu = jiayoulu_arr[jiayoulu_arr.length - 1][jiayoulu_arr[jiayoulu_arr.length - 1].length - 1];
                if (Global.isNotEmpty(jiayoulu)) {
                    if (jiayoulu["color"] == 0) {
                        this.playPanel.wenlu_xian_jiayoulu.source = "wjl_dxx_h"
                    } else if (jiayoulu["color"] == 1) {
                        this.playPanel.wenlu_xian_jiayoulu.source = "wjl_dxx_l"
                    }
                }
            }
            WjlVO.getVo().ludan.shift()
        }
        //珠盘路
        private showZhuPanLu() {
            var ludan = WjlVO.getVo().ludan;
            var leng = ludan.length
            var BankWinNum = 0//庄赢次数
            var PlayerWinNum = 0//闲赢次数
            var HeWinNum = 0//和赢次数
            var BankerTwoPairNum = 0//庄对子次数 
            var PlayerTwoPairNum = 0//闲对子次数
            var xingYun6 = 0//幸运6次数
            var List: Array<Array<Number>> = []
            var lie = 0
            var hang = 0
            var setType = function (lie, hang, type) {
                if (List[lie] == null) {
                    List[lie] = [];
                }
                List[lie][hang] = type
            }
            for (let i = leng - 1; i >= 0; i--) {
                var data = ludan[i];
                var cbBankerCount = data["cbBankerCount"]
                var cbPlayerCount = data["cbPlayerCount"]
                var bBankerTwoPair = data["bBankerTwoPair"]
                var bPlayerTwoPair = data["bPlayerTwoPair"]
                var type = null;//0庄1闲2和
                if (cbBankerCount > cbPlayerCount) {
                    BankWinNum++
                    type = 0
                } else if (cbBankerCount < cbPlayerCount) {
                    PlayerWinNum++
                    type = 1
                } else if (cbBankerCount == cbPlayerCount) {
                    HeWinNum++
                    type = 2
                }
                if (cbBankerCount == 6) {
                    xingYun6++
                }
                if (bBankerTwoPair) {
                    BankerTwoPairNum++
                }
                if (bPlayerTwoPair) {
                    PlayerTwoPairNum++
                }
                setType(lie, hang, type);
                hang++
                if (hang != 0 && hang % 6 == 0) {
                    lie++
                    hang = 0
                }
            }
            //珠盘路
            if (List.length > 7) {
                List = List.slice(-7)
            }
            for (let i = 0; i < this.playPanel.ludan_group_zhupanlu.numChildren; i++) {
                if (this.playPanel.ludan_group_zhupanlu.getChildAt(i) instanceof eui.Image) {
                    betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_zhupanlu.getChildAt(i))
                }
            }
            this.playPanel.ludan_group_zhupanlu.removeChildren();
            var img;
            for (let i = 0; i < List.length; i++) {
                for (let k = 0; k < List[i].length; k++) {
                    var num = List[i][k];
                    var imgName = ""
                    if (num == 0) {
                        imgName = "wjl_win_zhuang"
                    } else if (num == 1) {
                        imgName = "wjl_win_xian"
                    } else if (num == 2) {
                        imgName = "wjl_win_he"
                    }
                    img = betImgPool.getFreeObject(imgName)
                    img.x = i * 40 + 3
                    img.y = k * 40 + 3
                    this.playPanel.ludan_group_zhupanlu.addChild(img);
                }
            }
            if (img) {
                EffectUtils.Twinkle(img)
            }
            //文字
            this.playPanel.ludan_zhuang_num.text = BankWinNum + ""
            this.playPanel.ludan_xian_num.text = PlayerWinNum + ""
            this.playPanel.ludan_he_num.text = HeWinNum + ""
            this.playPanel.ludan_zDuizi_num.text = BankerTwoPairNum + ""
            this.playPanel.ludan_xDuizi_num.text = PlayerTwoPairNum + ""
            this.playPanel.ludan_xy6num.text = xingYun6 + ""
            this.playPanel.ludan_jushu.text = leng + ""

        }
        //大路
        private showDaLu(): Array<Array<Object>> {
            //大路
            // 大路是一个6行但列数很多的网格状图，记录时红圈代表庄赢，蓝圈代表闲赢。当赢家变为另一方时就要开始新的一列，所以大路会是红蓝圈交替的列。和局在大路中不使用单独的圈来显示，只有在上一手牌的圈上加一个数字，连续和局该数字累加
            //设计思路 把我们要生成的不管是蓝色还是红色还是文字，都按object的形式装进二维数组，，obj["zhuang"]=1 表示红色图片。obj["xian"]=1表示蓝色图片，obj["he"]=？表示有几次和局，之后遍历二维数组来生成视图，二维数组的两个下标作为XY坐标
            var arr = WjlVO.getVo().ludan;
            var leng = arr.length
            var List: Array<Array<Object>> = [[]];
            var hang = 0//竖坐标
            var lie = 0//横坐标
            var maxHang = 5;//1列最多6行，若第2列的第6行被第1列向右延申占领了，第2列就只能最大5行
            var upType = null//上一次是什么 0庄 1闲 2和
            //从数组指定位置获取对象，没有就创建
            var getObj = function (lie, hang): Object {
                if (List[lie] != null) {
                    if (List[lie][hang] != null) {
                        return List[lie][hang]
                    }
                }
                if (List[lie] == null) {
                    List[lie] = [];
                }
                if (List[lie][hang] == null) {
                    List[lie][hang] = {
                        zhuang: 0,
                        xian: 0,
                        he: 0,
                        zhuangDui: false,
                        xianDui: false
                    }
                }
                return List[lie][hang]
            }
            var find = function (lie, hang): Boolean {
                if (List[lie] != null) {
                    if (List[lie][hang] != null) {
                        return true
                    }
                }
                return false;
            }
            for (let i = leng - 1; i >= 0; i--) {
                var data = arr[i];
                var cbBankerCount = data["cbBankerCount"]
                var cbPlayerCount = data["cbPlayerCount"]
                var bBankerTwoPair = data["bBankerTwoPair"]
                var bPlayerTwoPair = data["bPlayerTwoPair"]

                var type = null;
                if (cbBankerCount > cbPlayerCount) {
                    type = 0
                } else if (cbBankerCount < cbPlayerCount) {
                    type = 1
                } else if (cbBankerCount == cbPlayerCount) {
                    type = 2
                }
                if (type != 2) {//和局不换位置 不记录
                    if (upType != null) {//前面没记录就不换位置，但是当前不是和局要记录
                        if (type == upType) {//向下换行
                            hang++;
                            if (hang > maxHang) {//超出最大行要向右换列
                                hang = maxHang
                                lie++
                            }
                            if (find(lie, hang)) {//该行已被占位要向右换列
                                maxHang = hang - 1;
                                hang = maxHang
                                lie++
                            }
                        } else {//向右换列 不能使用现有的列,因为行不足6的时候列会向右延申。应该读取数组 ，哪一行第0个是空就是用该位置的列
                            hang = 0
                            maxHang = 5;//因图片变化导致向右换列，最大行恢复为6
                            //找到下一列,
                            for (let b = 0; b < List.length; b++) {
                                if (find(b, 0)) {
                                    lie = b + 1
                                } else {
                                    break
                                }
                            }
                        }
                    }
                    upType = type;
                }
                //行列决定后生成该位置的数据
                var obj = getObj(lie, hang)
                if (type == 0) {
                    obj["zhuang"] = 1
                }
                if (type == 1) {
                    obj["xian"] = 1
                }
                if (type == 2) {
                    obj["he"] += 1
                }
                if (bBankerTwoPair) {
                    obj["zhuangDui"] = true
                }
                if (bPlayerTwoPair) {
                    obj["xianDui"] = true
                }
            }
            //最后根据数组生成视图
            for (let i = 0; i < this.playPanel.ludan_group_dalu.numChildren; i++) {
                if (this.playPanel.ludan_group_dalu.getChildAt(i) instanceof eui.Image) {
                    betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_dalu.getChildAt(i))
                }
            }
            this.playPanel.ludan_group_dalu.removeChildren()
            if (List.length > 23) {
                List = List.slice(-23)
            }
            for (let i = 0; i < List.length; i++) {
                let List2: Array<Object> = List[i]
                for (let j = 0; j < List2.length; j++) {
                    let obj = List2[j]
                    if (obj != null) {
                        if (obj["zhuang"] == 1) {
                            let img = betImgPool.getFreeObject("wjl_dy_h")
                            img.x = i * 19.2;
                            img.y = j * 21;
                            this.playPanel.ludan_group_dalu.addChild(img)
                        }
                        if (obj["xian"] == 1) {
                            let img = betImgPool.getFreeObject("wjl_dy_l")
                            img.x = i * 19.2;
                            img.y = j * 21;
                            this.playPanel.ludan_group_dalu.addChild(img)
                        }
                        if (obj["zhuangDui"] == true) {
                            let img = betImgPool.getFreeObject("wjl_sx_h")
                            img.x = i * 19.2 + 2;
                            img.y = j * 21 + 2;
                            this.playPanel.ludan_group_dalu.addChild(img)
                        }
                        if (obj["xianDui"] == true) {
                            let img = betImgPool.getFreeObject("wjl_sx_l");
                            img.x = i * 19.2 + 8;
                            img.y = j * 21 + 8;
                            this.playPanel.ludan_group_dalu.addChild(img)
                        }
                        if (obj["he"] > 0) {
                            let text = new eui.Label(obj["he"] + "")
                            text.x = i * 19.2 + 2;
                            text.y = j * 21;
                            text.size = 20
                            text.textColor = 0x67BC0B
                            this.playPanel.ludan_group_dalu.addChild(text)
                        }
                    }
                }
            }
            return List;
        }
        private honglanList: Array<Array<number>> = [];//红蓝混合不包含“和”的数组，用来生成 大眼仔 小路 和甲由路,省去小路和甲由路生成这个数组的工作量
        //大眼仔路 
        //ludan 路单数据，显示视图时使用VO中的实时路单数据，问路时传入新增过庄赢或者闲赢模拟的路单数据 
        //wenlu 是否问路调用。计算庄问路时服用此方法但不用刷新视图，而是返回计算后的数组
        private sohwDaYanZai(wenlu: boolean = false) {
            var ludan = WjlVO.getVo().ludan
            var leng = ludan.length
            var list: Array<Array<number>> = [[]];
            var hang = 0//竖坐标
            var lie = 0//横坐标
            var upType = null//上一次是什么 0庄 1闲 2和
            //生成大眼仔视图 根据大路,但是超出6个还是不拐弯
            for (let i = leng - 1; i >= 0; i--) {
                var data = ludan[i];
                var cbBankerCount = data["cbBankerCount"]
                var cbPlayerCount = data["cbPlayerCount"]
                var type = null;
                if (cbBankerCount > cbPlayerCount) {
                    type = 0
                } else if (cbBankerCount < cbPlayerCount) {
                    type = 1
                } else if (cbBankerCount == cbPlayerCount) {
                    type = 2
                }
                if (type != 2) {//和局不换位置 不记录
                    if (upType != null) {//前面没记录就不换位置，但是当前不是和局要记录
                        if (type == upType) {//向下换行
                            hang++;
                        } else {//向右换列
                            hang = 0
                            lie++
                        }
                    }
                    upType = type;
                }
                //行列决定后生成该位置的数据占位
                if (list[lie] == null) {
                    list[lie] = [];
                }
                if (list[lie][hang] == null) {
                    list[lie][hang] = 1;
                }
            }
            this.honglanList = list;

            //根据上面生成的大路来生成大眼仔
            if (list.length < 2) {
                for (let i = 0; i < this.playPanel.ludan_group_dayanlu.numChildren; i++) {
                    if (this.playPanel.ludan_group_dayanlu.getChildAt(i) instanceof eui.Image) {
                        betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_dayanlu.getChildAt(i))
                    }
                }
                this.playPanel.ludan_group_dayanlu.removeChildren();
                return;
            }
            if (list.length == 2 && list[1].length < 2) {
                for (let i = 0; i < this.playPanel.ludan_group_dayanlu.numChildren; i++) {
                    if (this.playPanel.ludan_group_dayanlu.getChildAt(i) instanceof eui.Image) {
                        betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_dayanlu.getChildAt(i))
                    }
                }
                this.playPanel.ludan_group_dayanlu.removeChildren();
                return;
            }
            //先按大路红蓝色生成 红蓝共存的数组。再迭代数组生成纵横红蓝分离的视图
            var lie = 1;
            var hang = 1;
            var findIsNull = function (arr: Array<Array<Object>>, x, y) {
                if (arr.length > x) {
                    if (arr[x].length > y) {
                        return true;
                    }
                }
                return false;
            }
            var colorList = [];
            for (let i = lie; i < list.length; i++) {
                for (let k = hang; k < list[i].length; k++) {
                    var x = i;
                    var y = k;
                    var color = null;//0红1蓝
                    var change = false
                    if (k == 0) {//当前行列在列首时将当前行列移动到前列列尾,并且最终颜色要取反
                        x = i - 1
                        y = list[x].length
                        change = true
                    }
                    if (findIsNull(list, x - 1, y) && findIsNull(list, x - 1, y - 1)) { //连连拍
                        color = 0
                    }
                    if (!findIsNull(list, x - 1, y) && !findIsNull(list, x - 1, y - 1)) { //长庄/长闲
                        color = 0
                    }
                    if (!findIsNull(list, x - 1, y) && findIsNull(list, x - 1, y - 1)) { //两房1厅
                        color = 1
                    }
                    if (change) {
                        if (color == 0) {
                            color = 1;
                        } else {
                            color = 0;
                        }
                    }
                    colorList.push(color)
                }
                hang = 0;
            }
            //根据上面得到的红蓝混合数组生成红蓝分离的二维数组
            var arr: Array<Array<Object>> = []
            var hang = 0//竖坐标
            var lie = 0//横坐标
            var maxHang = 5;//1列最多6行，若第2列的第6行被第1列向右延申占领了，第2列就只能最大5行
            var upType = null//上一次是什么 0红 1蓝

            var getObj = function (lie, hang): Object {  //从数组指定位置获取对象，没有就创建
                if (arr[lie] != null) {
                    if (arr[lie][hang] != null) {
                        return arr[lie][hang]
                    }
                }
                if (arr[lie] == null) {
                    arr[lie] = [];
                }
                if (arr[lie][hang] == null) {
                    arr[lie][hang] = {
                        color: null
                    }
                }
                return arr[lie][hang]
            }
            var find = function (lie, hang): Boolean {
                if (arr[lie] != null) {
                    if (arr[lie][hang] != null) {
                        return true
                    }
                }
                return false;
            }
            for (let i = 0; i < colorList.length; i++) {
                var type = colorList[i];
                if (type == 0) {
                    type = 0
                } else {
                    type = 1
                }
                if (upType != null) {//前面没记录就不换位置，但是当前不是和局要记录
                    if (type == upType) {//向下换行
                        hang++;
                        if (hang > maxHang) {//超出最大行要向右换列
                            hang = maxHang
                            lie++
                        }
                        if (find(lie, hang)) {//该行已被占位要向右换列
                            maxHang = hang - 1;
                            hang = maxHang
                            lie++
                        }
                    } else {//向右换列 不能使用现有的列,因为行不足6的时候列会向右延申。应该读取数组 ，哪一行第0个是空就是用该位置的列
                        hang = 0
                        maxHang = 5;//因图片变化导致向右换列，最大行恢复为6
                        //找到下一列,
                        for (let b = 0; b < arr.length; b++) {
                            if (find(b, 0)) {
                                lie = b + 1
                            } else {
                                break
                            }
                        }
                    }
                }
                upType = type;
                //行列决定后生成该位置的数据
                var obj = getObj(lie, hang)
                obj["color"] = type
            }
            if (wenlu) {//问路不更新视图，直接返回最后得出的数组
                return arr
            }
            //最后根据红蓝分离的二维数组生成视图
            if (arr.length > 46) {
                arr = arr.slice(-46)
            }
            for (let i = 0; i < this.playPanel.ludan_group_dayanlu.numChildren; i++) {
                if (this.playPanel.ludan_group_dayanlu.getChildAt(i) instanceof eui.Image) {
                    betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_dayanlu.getChildAt(i))
                }
            }
            this.playPanel.ludan_group_dayanlu.removeChildren();
            for (let i = 0; i < arr.length; i++) {
                let List2: Array<Object> = arr[i]
                for (let j = 0; j < List2.length; j++) {
                    let obj = List2[j]
                    if (obj != null) {
                        if (obj["color"] == 0) {
                            let img = betImgPool.getFreeObject("wjl_xy_h")
                            img.x = i * 9.5;
                            img.y = j * 10;
                            this.playPanel.ludan_group_dayanlu.addChild(img)
                        }
                        if (obj["color"] == 1) {
                            let img = betImgPool.getFreeObject("wjl_xy_l")
                            img.x = i * 9.5;
                            img.y = j * 10;
                            this.playPanel.ludan_group_dayanlu.addChild(img)
                        }
                    }
                }
            }
        }
        //小路
        private showXiaoLu(wenlu: boolean = false) {
            //根据上面生成的大路来生成小路，规则跟大眼仔类似。不过大眼仔是与前一排比较，小路是于前2牌比叫。牌头前移还是只移一行
            var list = this.honglanList;
            if (list.length < 3) {
                for (let i = 0; i < this.playPanel.ludan_group_xiaolu.numChildren; i++) {
                    if (this.playPanel.ludan_group_xiaolu.getChildAt(i) instanceof eui.Image) {
                        betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_xiaolu.getChildAt(i))
                    }
                }
                this.playPanel.ludan_group_xiaolu.removeChildren();
                return;
            }
            if (list.length == 3 && list[2].length < 2) {
                for (let i = 0; i < this.playPanel.ludan_group_xiaolu.numChildren; i++) {
                    if (this.playPanel.ludan_group_xiaolu.getChildAt(i) instanceof eui.Image) {
                        betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_xiaolu.getChildAt(i))
                    }
                }
                this.playPanel.ludan_group_xiaolu.removeChildren();
                return;
            }
            //先按大路红蓝色生成 红蓝共存的数组。再迭代数组生成纵横红蓝分离的视图
            var lie = 2;
            var hang = 1;
            var findIsNull = function (arr: Array<Array<Object>>, x, y) {
                if (arr.length > x) {
                    if (arr[x].length > y) {
                        return true;
                    }
                }
                return false;
            }
            var colorList = [];
            for (let i = lie; i < list.length; i++) {
                for (let k = hang; k < list[i].length; k++) {
                    var x = i;
                    var y = k;
                    var color = null;//0红1蓝
                    var change = false
                    if (k == 0) {//当前行列在列首时将当前行列移动到前列列尾,并且最终颜色要取反
                        x = i - 1
                        y = list[x].length
                        change = true
                    }
                    if (findIsNull(list, x - 2, y) && findIsNull(list, x - 2, y - 1)) { //连连拍
                        color = 0
                    }
                    if (!findIsNull(list, x - 2, y) && !findIsNull(list, x - 2, y - 1)) { //长庄/长闲
                        color = 0
                    }
                    if (!findIsNull(list, x - 2, y) && findIsNull(list, x - 2, y - 1)) { //两房1厅
                        color = 1
                    }
                    if (change) {
                        if (color == 0) {
                            color = 1;
                        } else {
                            color = 0;
                        }
                    }
                    colorList.push(color)
                }
                hang = 0;
            }
            //根据上面得到的红蓝混合数组生成红蓝分离的二维数组
            var arr: Array<Array<Object>> = []
            var hang = 0//竖坐标
            var lie = 0//横坐标
            var maxHang = 5;//1列最多6行，若第2列的第6行被第1列向右延申占领了，第2列就只能最大5行
            var upType = null//上一次是什么 0红 1蓝

            var getObj = function (lie, hang): Object {  //从数组指定位置获取对象，没有就创建
                if (arr[lie] != null) {
                    if (arr[lie][hang] != null) {
                        return arr[lie][hang]
                    }
                }
                if (arr[lie] == null) {
                    arr[lie] = [];
                }
                if (arr[lie][hang] == null) {
                    arr[lie][hang] = {
                        color: null
                    }
                }
                return arr[lie][hang]
            }
            var find = function (lie, hang): Boolean {
                if (arr[lie] != null) {
                    if (arr[lie][hang] != null) {
                        return true
                    }
                }
                return false;
            }
            for (let i = 0; i < colorList.length; i++) {
                var color = colorList[i];
                if (upType != null) {//前面没记录就不换位置
                    if (color == upType) {//向下换行
                        hang++;
                        if (hang > maxHang) {//超出最大行要向右换列
                            hang = maxHang
                            lie++
                        }
                        if (find(lie, hang)) {//该行已被占位要向右换列
                            maxHang = hang - 1;
                            hang = maxHang
                            lie++
                        }
                    } else {//向右换列 不能使用现有的列,因为行不足6的时候列会向右延申。应该读取数组 ，哪一行第0个是空就是用该位置的列
                        hang = 0
                        maxHang = 5;//因图片变化导致向右换列，最大行恢复为6
                        //找到下一列,
                        for (let b = 0; b < arr.length; b++) {
                            if (find(b, 0)) {
                                lie = b + 1
                            } else {
                                break
                            }
                        }
                    }
                }
                upType = color;
                //行列决定后生成该位置的数据
                var obj = getObj(lie, hang)
                obj["color"] = color
            }
            if (wenlu) {//问路不更新视图，直接返回最后得出的数组
                return arr
            }
            //最后根据红蓝分离的二维数组生成视图
            if (arr.length > 12) {
                arr = arr.slice(-12)
            }
            for (let i = 0; i < this.playPanel.ludan_group_xiaolu.numChildren; i++) {
                if (this.playPanel.ludan_group_xiaolu.getChildAt(i) instanceof eui.Image) {
                    betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_xiaolu.getChildAt(i))
                }
            }
            this.playPanel.ludan_group_xiaolu.removeChildren();
            for (let i = 0; i < arr.length; i++) {
                let List2: Array<Object> = arr[i]
                for (let j = 0; j < List2.length; j++) {
                    let obj = List2[j]
                    if (obj != null) {
                        if (obj["color"] == 0) {
                            let img = betImgPool.getFreeObject("wjl_sx_h")
                            img.x = i * 9.5;
                            img.y = j * 10;
                            this.playPanel.ludan_group_xiaolu.addChild(img)
                        }
                        if (obj["color"] == 1) {
                            let img = betImgPool.getFreeObject("wjl_sx_l")
                            img.x = i * 9.5;
                            img.y = j * 10;
                            this.playPanel.ludan_group_xiaolu.addChild(img)
                        }
                    }
                }
            }
        }
        //甲由路
        private showJiaYouLu(wenlu: boolean = false) {
            //根据上面生成的大路来生成小路，规则跟大眼仔类似。不过大眼仔是与前一排比较，小路是于前2牌比叫。牌头前移还是只移一行
            var list = this.honglanList;
            if (list.length < 4) {
                for (let i = 0; i < this.playPanel.ludan_group_jiayoulu.numChildren; i++) {
                    if (this.playPanel.ludan_group_jiayoulu.getChildAt(i) instanceof eui.Image) {
                        betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_jiayoulu.getChildAt(i))
                    }
                }
                this.playPanel.ludan_group_jiayoulu.removeChildren();
                return;
            }
            if (list.length == 4 && list[2].length < 2) {
                for (let i = 0; i < this.playPanel.ludan_group_jiayoulu.numChildren; i++) {
                    if (this.playPanel.ludan_group_jiayoulu.getChildAt(i) instanceof eui.Image) {
                        betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_jiayoulu.getChildAt(i))
                    }
                }
                this.playPanel.ludan_group_jiayoulu.removeChildren();
                return;
            }
            //先按大路红蓝色生成 红蓝共存的数组。再迭代数组生成纵横红蓝分离的视图
            var lie = 3;
            var hang = 1;
            var findIsNull = function (arr: Array<Array<Object>>, x, y) {
                if (arr.length > x) {
                    if (arr[x].length > y) {
                        return true;
                    }
                }
                return false;
            }
            var colorList = [];
            for (let i = lie; i < list.length; i++) {
                for (let k = hang; k < list[i].length; k++) {
                    var x = i;
                    var y = k;
                    var color = null;//0红1蓝
                    var change = false
                    if (k == 0) {//当前行列在列首时将当前行列移动到前列列尾,并且最终颜色要取反
                        x = i - 1
                        y = list[x].length
                        change = true
                    }
                    if (findIsNull(list, x - 3, y) && findIsNull(list, x - 3, y - 1)) { //连连拍
                        color = 0
                    }
                    if (!findIsNull(list, x - 3, y) && !findIsNull(list, x - 3, y - 1)) { //长庄/长闲
                        color = 0
                    }
                    if (!findIsNull(list, x - 3, y) && findIsNull(list, x - 3, y - 1)) { //两房1厅
                        color = 1
                    }
                    if (change) {
                        if (color == 0) {
                            color = 1;
                        } else {
                            color = 0;
                        }
                    }
                    colorList.push(color)
                }
                hang = 0;
            }
            //根据上面得到的红蓝混合数组生成红蓝分离的二维数组
            var arr: Array<Array<Object>> = []
            var hang = 0//竖坐标
            var lie = 0//横坐标
            var maxHang = 5;//1列最多6行，若第2列的第6行被第1列向右延申占领了，第2列就只能最大5行
            var upType = null//上一次是什么 0红 1蓝

            var getObj = function (lie, hang): Object {  //从数组指定位置获取对象，没有就创建
                if (arr[lie] != null) {
                    if (arr[lie][hang] != null) {
                        return arr[lie][hang]
                    }
                }
                if (arr[lie] == null) {
                    arr[lie] = [];
                }
                if (arr[lie][hang] == null) {
                    arr[lie][hang] = {
                        color: null
                    }
                }
                return arr[lie][hang]
            }
            var find = function (lie, hang): Boolean {
                if (arr[lie] != null) {
                    if (arr[lie][hang] != null) {
                        return true
                    }
                }
                return false;
            }
            for (let i = 0; i < colorList.length; i++) {
                var color = colorList[i];
                if (upType != null) {//前面没记录就不换位置
                    if (color == upType) {//向下换行
                        hang++;
                        if (hang > maxHang) {//超出最大行要向右换列
                            hang = maxHang
                            lie++
                        }
                        if (find(lie, hang)) {//该行已被占位要向右换列
                            maxHang = hang - 1;
                            hang = maxHang
                            lie++
                        }
                    } else {//向右换列 不能使用现有的列,因为行不足6的时候列会向右延申。应该读取数组 ，哪一行第0个是空就是用该位置的列
                        hang = 0
                        maxHang = 5;//因图片变化导致向右换列，最大行恢复为6
                        //找到下一列,
                        for (let b = 0; b < arr.length; b++) {
                            if (find(b, 0)) {
                                lie = b + 1
                            } else {
                                break
                            }
                        }
                    }
                }
                upType = color;
                //行列决定后生成该位置的数据
                var obj = getObj(lie, hang)
                obj["color"] = color
            }
            if (wenlu) {//问路不更新视图，直接返回最后得出的数组
                return arr
            }
            //最后根据红蓝分离的二维数组生成视图
            if (arr.length > 12) {
                arr = arr.slice(-12)
            }
            for (let i = 0; i < this.playPanel.ludan_group_jiayoulu.numChildren; i++) {
                if (this.playPanel.ludan_group_jiayoulu.getChildAt(i) instanceof eui.Image) {
                    betImgPool.returnObject(<eui.Image>this.playPanel.ludan_group_jiayoulu.getChildAt(i))
                }
            }
            this.playPanel.ludan_group_jiayoulu.removeChildren();
            for (let i = 0; i < arr.length; i++) {
                let List2: Array<Object> = arr[i]
                for (let j = 0; j < List2.length; j++) {
                    let obj = List2[j]
                    if (obj != null) {
                        if (obj["color"] == 0) {
                            let img = betImgPool.getFreeObject("wjl_xx_h")
                            img.x = i * 9.5;
                            img.y = j * 10;
                            this.playPanel.ludan_group_jiayoulu.addChild(img)
                        }
                        if (obj["color"] == 1) {
                            let img = betImgPool.getFreeObject("wjl_xx_l")
                            img.x = i * 9.5;
                            img.y = j * 10;
                            this.playPanel.ludan_group_jiayoulu.addChild(img)
                        }
                    }
                }
            }
        }
        //点击筹码组，为处于下注状态给出提示
        private betGroupClick() {
            if (this.playPanel.xiazhu_tips.source != "timeState_xiazhu") {
                EffectUtils.textFadeAway("非下注状态，请等待...")
            }
        }
        //选择筹码
        private onChipClick(event: egret.TouchEvent): void {
            for (var i = 0; i < 5; i++) {
                if (this.playPanel["bet_" + i] != event.currentTarget) {
                    this.playPanel["bet_" + i].name = '';
                    egret.Tween.removeTweens(this.playPanel["bet_" + i + "_bg"])
                    this.playPanel["bet_" + i + "_bg"].visible = false;
                    this.playPanel["bet_" + i + "_bg"].rotation = 0;
                } else {
                    if (event.currentTarget.name != 'ok') {
                        event.currentTarget.name = 'ok';
                        this.playPanel["bet_" + i + "_bg"].rotation = 0;
                        this.playPanel["bet_" + i + "_bg"].visible = true;
                        EffectUtils.rotationEffect(this.playPanel["bet_" + i + "_bg"])
                        EffectUtils.playDim(event.currentTarget)
                        this.selectBet = event.currentTarget;
                    }
                }
            }
        }
        //点击桌面下注
        private onRectClick(event: egret.TouchEvent): void {
            let bet_button_bg: eui.Image = null;
            let betArea;
            let myBetNum = 0;
            if (event.currentTarget == this.playPanel.bet_button_0) {
                bet_button_bg = this.playPanel.bet_button_bg_0;
                betArea = 6//坐标看本页头部注释
                myBetNum = WjlVO.getVo().betNumAdds_0_my
            }
            if (event.currentTarget == this.playPanel.bet_button_1) {
                bet_button_bg = this.playPanel.bet_button_bg_1;
                betArea = 1
                myBetNum = WjlVO.getVo().betNumAdds_1_my
            }
            if (event.currentTarget == this.playPanel.bet_button_2) {
                bet_button_bg = this.playPanel.bet_button_bg_2;
                betArea = 7
                myBetNum = WjlVO.getVo().betNumAdds_2_my
            }
            if (event.currentTarget == this.playPanel.bet_button_3) {
                bet_button_bg = this.playPanel.bet_button_bg_3;
                betArea = 0
                myBetNum = WjlVO.getVo().betNumAdds_3_my
            }
            if (event.currentTarget == this.playPanel.bet_button_4) {
                bet_button_bg = this.playPanel.bet_button_bg_4;
                betArea = 8
                myBetNum = WjlVO.getVo().betNumAdds_4_my
            }
            if (event.currentTarget == this.playPanel.bet_button_5) {
                bet_button_bg = this.playPanel.bet_button_bg_5;
                betArea = 2
                myBetNum = WjlVO.getVo().betNumAdds_5_my
            }
            let imgNum;
            for (var i = 0; i < 5; i++) {
                if (this.playPanel["bet_" + i].name == 'ok') {
                    imgNum = this.bet_chip[i];
                    break;
                }
            }
            if (!imgNum) {
                return;
            }
            if (bet_button_bg) {
                egret.Tween.get(bet_button_bg).to({ visible: true }).wait(100).to({ visible: false }).call(() => {
                    egret.Tween.removeTweens(bet_button_bg)
                }, this);
            }
            if (WjlVO.getVo().lUserScore < 5000) {
                EffectUtils.textFadeAway("抱歉，50 筹码以上才能下注!");
                this.IsUserScore(0)
                return;
            }
            if (WjlVO.getVo().lUserScore < imgNum) {
                EffectUtils.textFadeAway("金币不足!");
                return;
            }
            if ((myBetNum + imgNum) > WjlVO.getVo().lAreaLimitScore) {
                EffectUtils.textFadeAway("区域限制最多下注" + WjlVO.getVo().lAreaLimitScore / 100 + "元!");
                return;
            }
            let obj = {
                cbBetArea: betArea,
                lBetScore: imgNum
            }
            SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.WJL, RegDataWjl.CMD_GP_UserAddScore, obj, false);
        }
        /**
         * 更改筹.码按钮状态
         * num:手头金额
         * xiazhu：是否下注后重置
         * startXiazhu：是否开局重置
         */
        private selectBet: eui.Button = null;
        public IsUserScore(num: number, xiazhu: boolean = false, startXiazhu: boolean = false) {
            //找出上次选中的筹码，若本轮金币不足导致筹码被取消选择，则筹码自动选择更低的
            let img = null;
            let modify = false;
            for (var i = 0; i < 5; i++) {
                if (this.playPanel['bet_' + i].name == 'ok') {
                    img = this.playPanel['bet_' + i];
                    break;
                }
            }
            var bet4 = Number(this.playPanel.bet_4.label) * 100
            var bet3 = Number(this.playPanel.bet_3.label) * 100
            var bet2 = Number(this.playPanel.bet_2.label) * 100
            var bet1 = Number(this.playPanel.bet_1.label) * 100
            var bet0 = Number(this.playPanel.bet_0.label) * 100
            if (num < bet4) {
                this.playPanel.bet_4.enabled = false
                this.playPanel.bet_4.name = ""
                this.playPanel.bet_4.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_4_bg.visible = false;
                this.playPanel.bet_4_bg.rotation = 0;
                egret.Tween.get(this.playPanel.bet_4_bg)
                if (img == this.playPanel.bet_4) {
                    modify = true;
                }
            } else {
                this.playPanel.bet_4.enabled = true
                this.playPanel.bet_4.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_4.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
            }
            if (num < bet3) {
                this.playPanel.bet_3.enabled = false
                this.playPanel.bet_3.name = ""
                this.playPanel.bet_3.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_3_bg.visible = false;
                this.playPanel.bet_3_bg.rotation = 0;
                egret.Tween.get(this.playPanel.bet_3_bg)
                if (img == this.playPanel.bet_3) {
                    modify = true;
                }
            } else {
                this.playPanel.bet_3.enabled = true
                this.playPanel.bet_3.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_3.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
            }
            if (num < bet2) {
                this.playPanel.bet_2.enabled = false
                this.playPanel.bet_2.name = ""
                this.playPanel.bet_2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_2_bg.visible = false;
                this.playPanel.bet_2_bg.rotation = 0;
                egret.Tween.get(this.playPanel.bet_2_bg)
                if (img == this.playPanel.bet_2) {
                    modify = true;
                }
            } else {
                this.playPanel.bet_2.enabled = true
                this.playPanel.bet_2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
            }
            if (num < bet1) {
                this.playPanel.bet_1.enabled = false
                this.playPanel.bet_1.name = ""
                this.playPanel.bet_1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_1_bg.visible = false;
                this.playPanel.bet_1_bg.rotation = 0;
                egret.Tween.get(this.playPanel.bet_1_bg)
                if (img == this.playPanel.bet_1) {
                    modify = true;
                }
            } else {
                this.playPanel.bet_1.enabled = true
                this.playPanel.bet_1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
            }
            if (num < bet0) {
                this.playPanel.bet_0.enabled = false
                this.playPanel.bet_0.name = ""
                this.playPanel.bet_0.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_0_bg.visible = false;
                this.playPanel.bet_0_bg.rotation = 0;
                egret.Tween.get(this.playPanel.bet_0_bg)
                if (img == this.playPanel.bet_0) {
                    modify = true;
                }
            } else {
                this.playPanel.bet_0.enabled = true
                this.playPanel.bet_0.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
                this.playPanel.bet_0.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onChipClick, this);
            }
            //因下注导致钱不够筹码更换
            if ((xiazhu && modify)) {
                if (num >= bet4) {
                    this.playPanel.bet_4.name = "ok";
                    this.playPanel.bet_4_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_4_bg);
                    this.selectBet = this.playPanel.bet_4;
                } else if (num >= bet3) {
                    this.playPanel.bet_3.name = "ok";
                    this.playPanel.bet_3_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_3_bg);
                    this.selectBet = this.playPanel.bet_3;
                } else if (num >= bet2) {
                    this.playPanel.bet_2.name = "ok";
                    this.playPanel.bet_2_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_2_bg);
                    this.selectBet = this.playPanel.bet_2;
                } else if (num >= bet1) {
                    this.playPanel.bet_1.name = "ok";
                    this.playPanel.bet_1_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_1_bg);
                    this.selectBet = this.playPanel.bet_1;
                } else if (num >= bet0) {
                    this.playPanel.bet_0.name = "ok";
                    this.playPanel.bet_0_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_0_bg);
                    this.selectBet = this.playPanel.bet_0;
                }
                if (num < 100) {
                    EffectUtils.textFadeAway("金币不足，无法下注");
                } else {
                    EffectUtils.textFadeAway("金币不足，已自动切换筹码");
                }
            }
            //新开局时上一局最后选中的筹码如果这一局依然可用则自动选中
            if (startXiazhu && this.selectBet != null) {
                if (num >= bet4 && this.selectBet == this.playPanel.bet_4) {
                    this.playPanel.bet_4.name = "ok"
                    this.playPanel.bet_4_bg.rotation = 0;
                    this.playPanel.bet_4_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_4_bg)
                }
                if (num >= bet3 && this.selectBet == this.playPanel.bet_3) {
                    this.playPanel.bet_3.name = "ok"
                    this.playPanel.bet_3_bg.rotation = 0;
                    this.playPanel.bet_3_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_3_bg)
                }
                if (num >= bet2 && this.selectBet == this.playPanel.bet_2) {
                    this.playPanel.bet_2.name = "ok"
                    this.playPanel.bet_2_bg.rotation = 0;
                    this.playPanel.bet_2_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_2_bg)
                }
                if (num >= bet1 && this.selectBet == this.playPanel.bet_1) {
                    this.playPanel.bet_1.name = "ok"
                    this.playPanel.bet_1_bg.rotation = 0;
                    this.playPanel.bet_1_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_1_bg)
                }
                if (num >= bet0 && this.selectBet == this.playPanel.bet_0) {
                    this.playPanel.bet_0.name = "ok"
                    this.playPanel.bet_0_bg.rotation = 0;
                    this.playPanel.bet_0_bg.visible = true;
                    EffectUtils.rotationEffect(this.playPanel.bet_0_bg)
                }
            }
        }
        //金币拆分
        private qiegeJinbi(fen: number): Array<any> {
            let Fen = fen
            let imgList: Array<any> = [];
            let guigeList = this.bet_chip;
            for (let j = guigeList.length; j >= 0; j--) {
                let len = Math.floor(Fen / guigeList[j]);
                if (len != 0) {
                    for (var k = 0; k < len; k++) {
                        imgList.push(guigeList[j]);
                        Fen -= guigeList[j];
                    }
                }
            }
            return imgList
        }
        //生成指定的随机数
        private random_num(min: number, max: number) {
            let Range = max - min;
            let Rand = Math.random();
            return (min + Math.round(Rand * Range));
        }
        //发牌报点
        //num已翻几张牌
        //adds 0闲家 1庄家
        private baodian(pokerObjArr: Array<Poker_public>, num, adds): string {
            var dian = 0;
            for (var i = 0; i < num; i++) {
                var poker = pokerObjArr[i]
                if (poker.value < 10) {
                    dian += poker.value
                }
            }
            var str = String(dian)
            var str2 = str.substring(str.length - 1, str.length)
            if (adds == 0) {
                this.playPanel.xian_dian.text = str2 + " ."
                EffectUtils.Stretch(this.playPanel.xian_dian)
            } else {
                this.playPanel.zhuang_dian.text = str2 + " ."
                EffectUtils.Stretch(this.playPanel.zhuang_dian)
            }
            SoundManage.startYinxiaoLoad("no_" + str2 + "_cn_mp3");
            return str2
        }
        //点击下拉菜单
        private menu_click() {
            if (this.playPanel.menu_button.name == "on") {//收起菜单
                egret.Tween.removeTweens(this.playPanel.menu_button)
                egret.Tween.removeTweens(this.playPanel.menu_group)
                this.playPanel.menu_button.name = "off"
                egret.Tween.get(this.playPanel.menu_button).to({ rotation: 0 }, 300)
                egret.Tween.get(this.playPanel.menu_group).to({ x: -260 }, 300).call((menu_group: eui.Group) => {
                    menu_group.visible = false;
                }, this, [this.playPanel.menu_group])
            } else {                                      //弹出菜单
                egret.Tween.removeTweens(this.playPanel.menu_button)
                egret.Tween.removeTweens(this.playPanel.menu_group)
                this.playPanel.menu_button.name = "on"
                this.playPanel.menu_group.visible = true;
                egret.Tween.get(this.playPanel.menu_button).to({ rotation: 90 }, 300)
                egret.Tween.get(this.playPanel.menu_group).to({ x: 0 }, 300)
            }
        }
        //点击设置
        private setClick() {
            SoundManage.startAnniuBtnLoad();
            this.menu_click();
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_SETTING)
        }
        //点击帮助
        private helpClick() {
            SoundManage.startAnniuBtnLoad();
            this.menu_click();
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_HELP_WJL)
        }
        //点击反馈
        private fankuiClick() {
            SoundManage.startAnniuBtnLoad();
            this.menu_click();
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_FANKUI, InstructionsEnum.GAME_TYPE_NAME.WJL)
        }
        //点击记录
        private jiluClick() {
            SoundManage.startAnniuBtnLoad();
            this.menu_click();
            var obj = {
                gameType: InstructionsEnum.GAME_TYPE_NAME.WJL,
                roomType: InstructionsEnum.LEVEL_GAME
            }
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_JILU, JSON.stringify(obj))
        }
        //点击退出
        private exitClick() {
            SoundManage.startAnniuBtnLoad();
            this.menu_click();
            if (WjlVO.getVo().game_state == 2) {
                let obj = new Object();
                obj[InstructionsEnum.TEXT] = "您已下注，请等待游戏结束后离开！";
                game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_TIP, obj);
            } else {
                let obj = new Object();
                obj[InstructionsEnum.CODE] = PanelNotify.WJL.CLOSE_PLAY_GAME;
                obj[InstructionsEnum.TEXT] = "确定要离开游戏吗？";
                game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_TIP, obj);
            }
        }
        //点击玩家列表
        private userListClic() {
            SoundManage.startAnniuBtnLoad();
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_USER_LIST, InstructionsEnum.GAME_TYPE_NAME.WJL)
        }
    }

}


